package com.easywan.web.controller.seo;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.common.utils.Assert;
import com.easywan.core.BaseController;
import com.easywan.utils.HttpsUtils;

/**
 * whios查询
 * @author tank
 *
 */
@Controller
@RequestMapping("seo")
public class WhoisController extends BaseController{
	public static Logger logger = Logger.getLogger(BaseController.class);
	@RequestMapping("toWhois")
	public String toWhois(){
		return "seo/whois.jsp";
	}
	/**
	 * whois.aliyun.com/whois/domain/easywa.com
	 * @param request
	 * @param res
	 * @return
	 */
	@ResponseBody
	@RequestMapping("whois")
	public String whois(HttpServletRequest request){
		String url = request.getParameter("url");
		Assert.notNull(url, "没有查询地址");
		
		//判断域名是否为顶级域名  去掉前缀
		String[] urls = url.split("\\.");
		if(urls.length > 2){
			url = urls[urls.length - 2] + "." + urls[urls.length-1];
		}
		
		return getWhois(url);
	}
	//https://whois.aliyun.com/whois/api_whois?host=easywan.info&umToken=whois-web-hichina-com%3A67b183f0c2b54e3203b9d4132f29f92c&_=1499491397393
	public String getWhois(String url){
		//以下代码为service代码
		String html = null;
		try {
			html = HttpsUtils.doGet("https://whois.aliyun.com/whois/api_whois?host="+url+
					"&umToken=whois-web-hichina-com%3A67b183f0c2b54e3203b9d4132f29f92c&_=1499491397393",
					"cna=iCjlEf4SY3YCAa+/EZeETPAS; isg=Au7uNc0QO7mYYU_dJBccQB5BPkRwR7OH7WWpiBi3W_Gs-49VgH66-SS7xVzp; WHOIS_JSESSIONID=31666Z71-KGAM3UQ7NCD0X05CX1JS2-RQBGUU4J-19JL; whoistmp0=eNrzEHAMDfGId%2FH3dfT0i%2Fdz9HXlSU0srixPzNPLzEvL5w12DQ729PeL9%2FV3cfUxiKrOTLFSMjY0MzOLMjfU9XZ39DUODTT3c3YxiDAwdY4w9Ao20g0KdHIPDTXx0jW09PJR0kkusTI0sbQ0sTQ0tjAyMzHWSUyGC1gCoZFOboWVQW0UALTuJZs%3D; aliyun_choice=CN");
			//cna=iCjlEf4SY3YCAa+/EZeETPAS; isg=AtbWfSdyk8FA7adlHJ9kCEZZJowY3xvfRW2BUEA_eblVA3KdoQT1wfiz7aQR; WHOIS_JSESSIONID=31666Z71-KGAM3UQ7NCD0X05CX1JS2-RQBGUU4J-19JL; whoistmp0=eNrzEHAMDfGId%2FH3dfT0i%2Fdz9HXlSU0srixPzNPLzEvL5w12DQ729PeL9%2FV3cfUxiKrOTLFSMjY0MzOLMjfU9XZ39DUODTT3c3YxiDAwdY4w9Ao20g0KdHIPDTXx0jW09PJR0kkusTI0sbQ0sTQ0tjAyMzHWSUwGC5gaGRhaWhgZGevkVlgZ1EYBALRdJZA%3D; aliyun_choice=CN; _ga=GA1.2.108296827.1499491414; _gid=GA1.2.217308444.1499491414; _gat=1
		} catch (Exception e) {
			e.printStackTrace();
		}
		logger.info(html);
		return html;
	}
}
